package com.elitel.frame.base.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.elitel.frame.base.service.BaseRepconfigService;
import com.elitel.frame.main.dao.BaseRepconfigMapper;
import com.elitel.frame.main.dao.ext.ExtBaseRepconfigMapper;
import com.elitel.frame.main.entity.BaseRepconfig;
import com.elitel.frame.main.entity.ext.ReportRepconfigExt;

@Service
public class BaseRepconfigServiceImpl implements BaseRepconfigService{
	
	@Autowired
	private  ExtBaseRepconfigMapper extBaseRepconfigMapper;
	@Autowired
	private BaseRepconfigMapper baseRepconfigMapper;
	
	@Override
	public List<BaseRepconfig> selectRepConfigByRguid(String guid) {
		List<BaseRepconfig> list = extBaseRepconfigMapper.selectRepConfigByRguid(guid);
		return list;
	}
	@Override
	public List<ReportRepconfigExt> getAllRepconfig(String rguid) {
		List<ReportRepconfigExt> list = extBaseRepconfigMapper.getAllRepconfig(rguid);
		return list;
	}
	@Override
	public void insertRepconfig(String strFields,String rguid) {
		Map maps = (Map)JSON.parse(strFields);
		for (Object key : maps.keySet()) {
			BaseRepconfig bp = new BaseRepconfig();
			bp.setGuid(UUID.randomUUID().toString());
			bp.setRguid(rguid);
			bp.setRaguid(key.toString());
			bp.setPropvalue(maps.get(key).toString());
			baseRepconfigMapper.insertSelective(bp);
		}
	}
	@Override
	public void deleteRepconfigProp(String guids) {
		String[] id=guids.split(",");
		List<String> list=new ArrayList<String>();
		for (int i = 0; i < id.length; i++) {
			if(id[i]!=null && !"".equals(id[i])){
				list.add(id[i].trim());
			}
		}
		extBaseRepconfigMapper.deleteAllRepconfig(list);
		
	}
	@Override
	public void updateRepconfigProp(BaseRepconfig baseRepconfig) {
		baseRepconfigMapper.updateByPrimaryKeySelective(baseRepconfig);
		
	}

}
